package com.ruoyi.carowner.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.carowner.domain.CarownerWallet;
import com.ruoyi.carowner.service.ICarownerWalletService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车主钱包管理Controller
 *
 * @author aa
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/carowner/wallet")
public class CarownerWalletController extends BaseController {
    @Autowired
    private ICarownerWalletService carownerWalletService;


    @GetMapping("/getByUserId/{user_id}")
    public AjaxResult getByUserId(@PathVariable("user_id") Integer user_id) {
        return success(carownerWalletService.selectWalletListByUserid(user_id));
    }
    /**
     * 查询车主钱包管理列表
     */
    @PreAuthorize("@ss.hasPermi('carowner:wallet:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarownerWallet carownerWallet) {
        startPage();
        List<CarownerWallet> list = carownerWalletService.selectCarownerWalletList(carownerWallet);
        return getDataTable(list);
    }

    /**
     * 导出车主钱包管理列表
     */
    @PreAuthorize("@ss.hasPermi('carowner:wallet:export')")
    @Log(title = "车主钱包管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarownerWallet carownerWallet) {
        List<CarownerWallet> list = carownerWalletService.selectCarownerWalletList(carownerWallet);
        ExcelUtil<CarownerWallet> util = new ExcelUtil<CarownerWallet>(CarownerWallet.class);
        util.exportExcel(response, list, "车主钱包管理数据");
    }

    /**
     * 获取车主钱包管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('carowner:wallet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(carownerWalletService.selectCarownerWalletById(id));
    }

    /**
     * 新增车主钱包管理
     */
    @PreAuthorize("@ss.hasPermi('carowner:wallet:add')")
    @Log(title = "车主钱包管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarownerWallet carownerWallet) {
        return toAjax(carownerWalletService.insertCarownerWallet(carownerWallet));
    }

    /**
     * 修改车主钱包管理
     */
    @PreAuthorize("@ss.hasPermi('carowner:wallet:edit')")
    @Log(title = "车主钱包管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarownerWallet carownerWallet) {
        return toAjax(carownerWalletService.updateCarownerWallet(carownerWallet));
    }

    /**
     * 删除车主钱包管理
     */
    @PreAuthorize("@ss.hasPermi('carowner:wallet:remove')")
    @Log(title = "车主钱包管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(carownerWalletService.deleteCarownerWalletByIds(ids));
    }
}
